﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StoneStorage
{
    public partial class DictionaryForm : Form
    {
        public DictionaryForm(DataTable table, DataColumn visibleColumn, string formHeader)
        {
            if (visibleColumn == null)
            {
                throw new ArgumentNullException("visibleColumn");
            }

            if (formHeader == null)
            {
                throw new ArgumentNullException("formHeader");
            }

            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            InitializeComponent();

            this.Text = "Редактирование справочника: " + formHeader;
            
            BindingSource bs = new BindingSource();
            bs.DataSource = table.DataSet;
            bs.DataMember = table.TableName;
            
            dgvInvoice.DataSource = bs;
            dgvInvoice.Columns[visibleColumn.ColumnName].HeaderText = formHeader;
            dgvInvoice.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            HideColumnsExcept(visibleColumn);
        }

        private void HideColumnsExcept(DataColumn visibleColumn)
        {
            foreach (DataGridViewColumn column in dgvInvoice.Columns)
            {
                if (!(column.Name == visibleColumn.ColumnName))
                {
                    column.Visible = false;
                }
            }
        }

    }
}
